﻿@using AC.Code.Config
@{
    ViewBag.Title = "代码生成器";
    var lstDbServers = ViewData["DbServers"] as IList<string>;
    string serverName = ViewData["DbServer"].ToString();
    string dbName = ViewData["DbName"].ToString();
    string dbNameSource = ViewData["DbNameSource"].ToString();
    string dbTableSource = ViewData["DbTableSource"].ToString();

    var lstCodeLayerDesc = ViewData["lstCodeLayerDesc"] as IList<KeyValuePair<string, string>>;
    var lstDaoStyleDesc = ViewData["lstDaoStyleDesc"] as IList<KeyValuePair<string, string>>;
    var lstCallStyleDesc = ViewData["lstCallStyleDesc"] as IList<KeyValuePair<string, string>>;
}
@section HeadSection
{
    <link href="@Url.Content("~/Content/prettify.css")" type="text/css" rel="stylesheet"/>
    <script type="text/javascript" src="@Url.Content("~/Scripts/prettify.js")"></script>
    <script type="text/javascript">
        window.dbname = "@dbName";
    </script>
}
<div class="well row span11">
    <div class="span3">
        <form id="dbSelector" method="POST">
            <legend>配置条件</legend>
            <span class="hide alert-error" id="txtError"></span>
            <fieldset>
                <div class="control-group">
                    <label class="control-label" for="dbServer">选择服务器</label>
                    <div class="controls">
                        <div class="input-prepend">
                            <span class="add-on"><i class="icon-search"></i></span>
                            <select id="dbServer" name="dbServer">
                                @foreach (string dbServer in lstDbServers)
                                {
                                    <option @(dbServer == serverName ? @Html.Raw("selected='selected'").ToString() : string.Empty)>@dbServer</option>
                                }
                            </select>
                        </div>
                    </div>
                </div>

                <div class="control-group">
                    <label for="txtDbName" class="control-label">选择数据库</label>
                    <div class="controls">
                        <div class="input-append" id="divtest">
                            <span class="add-on"><i class="icon-search"></i></span>
                            <input type="text" id="txtDbName" name="dbName" value="@dbName" data-provide="typeahead" data-items="100" data-source="@dbNameSource"/>
                        </div>
                    </div>
                </div>

                <div class="control-group">
                    <label for="txtTableName" class="control-label">选择数据表</label>
                    <div class="controls">
                        <div class="input-append">
                            <span class="add-on"><i class="icon-search"></i></span>
                            <input type="text" id="txtTableName"  data-provide="typeahead" data-items="50" data-source="@dbTableSource"/>
                        </div>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
    <div class="span4 pull-left text-success">
        <table id="tdTableInfo" class="hide span11">
            <tr>
                <td>表名：</td>
                <td id="tdTableName"></td>
            </tr>
            <tr>
                <td>服务器：</td>
                <td id="tdDbServer"></td>
            </tr>
            <tr>
                <td>数据库：</td>
                <td id="tdDbName"></td>
            </tr>
            <tr>
                <td>表说明：</td>
                <td id="tdTableDesc"></td>
            </tr>
            <tr>
                <td colspan="2">
                    <a class="btn btn-large" id="btnCodeSettings">生成代码</a>
                    <a class="btn btn-large" id="btnGenerateJavaCode">生成Java代码</a>
                </td>
            </tr>
        </table>
    </div>
</div>
    
<div class="tabbable span11" id="tabResult">
    <ul class="nav nav-tabs">
        <li id="liColumnInfo" class="active"><a href="#tabColumnInfo" data-toggle="tab">表详细信息</a></li>
        <li id="liCodes"><a href="#tabCodes" data-toggle="tab">代码生成</a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tabColumnInfo">
        </div>
        <div class="tab-pane" id="tabCodes">
            <div>
                <a class="btn btn-link" id="btnGenerateCodeAndDownload">下载此代码</a>
            </div>
            <div class="tabbable tabs-left">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tabServiceDTO" data-toggle="tab">ServiceDTO</a></li>
                    <li><a href="#tabService" data-toggle="tab">Service</a></li>
                    <li><a href="#tabServiceImpl" data-toggle="tab">ServiceImpl</a></li>
                    <li><a href="#tabDomain" data-toggle="tab">Domain</a></li>
                    <li><a href="#tabDao" data-toggle="tab">Dao</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="tabServiceDTO">
                        <pre class="prettyprint linenums" id="codeOfServiceDTO"></pre>
                    </div>
                    <div class="tab-pane" id="tabService">
                        <pre class="prettyprint linenums" id="codeOfService"></pre>
                    </div>
                    <div class="tab-pane" id="tabServiceImpl">
                        <pre class="prettyprint linenums" id="codeOfServiceImpl"></pre>
                    </div>
                    <div class="tab-pane" id="tabDomain">
                        <pre class="prettyprint linenums" id="codeOfDomain"></pre>
                    </div>
                    <div class="tab-pane" id="tabDao">
                        <pre class="prettyprint linenums" id="codeOfDao"></pre>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="generateCodeSettings" class="modal hide fade">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
        <h3>代码生成参数</h3>
    </div>
    <div class="modal-body">
        <form class="form-horizontal">
            <fieldset>
                <div class="control-group">
                    <label class="control-label">所选择表：</label>
                    <div class="controls">
                        <input type="text" class="disabled uneditable-input" id="lblTableName" disabled="disabled"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="ddlCodeLayer">架构选择：</label>
                    <div class="controls">
                        <select id="ddlCodeLayer">
                            @foreach (var item in lstCodeLayerDesc)
                            {
                                <option title="@item.Value" value="@item.Key">@(((CodeLayer) Enum.Parse(typeof (CodeLayer), item.Key)).ToString())</option>
                            }
                        </select>
                        <p class="help-inline"></p>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="ddlDaoStyle">DAO实现：</label>
                    <div class="controls">
                        <select id="ddlDaoStyle">
                            @foreach (var item in lstDaoStyleDesc)
                            {
                                <option title="@item.Value" value="@item.Key">@(((DaoStyle) Enum.Parse(typeof (DaoStyle), item.Key)).ToString())</option>
                            }
                        </select>
                        <p class="help-inline"></p>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="ddlCallStyle">对象创建：</label>
                    <div class="controls">
                        <select id="ddlCallStyle">
                            @foreach (var item in lstCallStyleDesc)
                            {
                                <option title="@item.Value" value="@item.Key">@(((CallStyle) Enum.Parse(typeof (CallStyle), item.Key)).ToString())</option>
                            }
                        </select>
                        <p class="help-inline"></p>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
    <div class="modal-footer">
        <a id="btnGenerateCode" href="javascript:" class="btn btn-large">生成代码</a>
        <a href="javascript:" class="btn btn-large" data-dismiss="modal">关闭</a>
    </div>
</div>